package com.csii.activiti.server.core.variable.discover.impl;

import com.csii.activiti.server.abstraction.entity.ActUser;
import com.csii.activiti.server.abstraction.service.ActUserService;
import com.csii.activiti.server.core.constant.FlowNodeVariableTypeConstant;
import com.csii.activiti.server.core.entity.ActFlowNode;
import com.csii.activiti.server.core.variable.discover.ActVariableProcessorDiscover;
import org.activiti.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Component
public class ActFlowLeadVariableProcessor implements ActVariableProcessorDiscover {

    @Autowired
    private ActUserService actUserService;

    @Override
    public String getVariableName() {
        return "员工领导";
    }

    @Override
    public String getVariableType() {
        return FlowNodeVariableTypeConstant.LEAD;
    }

    @Override
    public boolean needManyPeopleReview() {
        return true;
    }

    @Override
    public boolean needEmptyProcessing() {
        return true;
    }

    @Override
    public int order() {
        return 0;
    }

    @Override
    public Set<String> getUsernames(ActFlowNode actFlowNode, String executionId, ExecutionEntityImpl processInstance) {
        List<ActUser> actUsers = actUserService.queryHisLeadershipByUsername(processInstance.getStartUserId());
        if (actUsers != null){
            return actUsers.stream().map(ActUser::getUsername).collect(Collectors.toSet());
        }
        return null;
    }
}
